<?php
/**
 * Created by PhpStorm.
 * User: 王柯 <wangke.email@foxmail.com>
 * Date: 2018\4\28 0028
 * Time: 15:16
 */
namespace wxpay\request;
use app\common\lib\wechat\WxCommon;
class WxWithdrawals{
    /**
     * 用户提现到银行卡
     * @param array $params 参数 *必传
     * @author 王柯 <wangke.email@foxmail.com>
     * @return array|bool|\mix|mixed|\stdClass|string
     */
    public static function query($params){
        /**
         *sdk字段说明
         *enc_bank_no 收款方银行卡号
         *enc_true_name 收款方用户名
         *bank_code 收款方开户行编号
         *amount 付款金额
         *partner_trade_no 转账订单编号
         *nonce_str 随机字符串
         */
        
        $wx = new WxCommon();

        //请求地址
        $url = 'https://api.mch.weixin.qq.com/mmpaysptrans/pay_bank';

        //流水号
        $data['partner_trade_no'] = $params['account_sn'];

        //商户id
        $data['mch_id'] = config('wxpay.merchant_id');

        //32位随机字符串
        $data['nonce_str'] = $wx::makeNonceStr(32);

        //收款方开户行编号
        $data['bank_code'] = $params['bank_code'];

        //收款方用户名(需rsa加密)
        $data['enc_true_name'] = $wx::rsaEncrypt($params['bank_full_name']);

        //收款方银行卡号(需rsa加密)
        $data['enc_bank_no'] = $wx::rsaEncrypt($params['bank_card']);

        //付款金额
        $data['amount'] = $params['total_amount'];

        //签名
        $data['sign'] = $wx::makeSign($data);

        //数组转xml
        $xml = $wx::arrayToXml($data);
        //halt($wx::getWxPublicKey());
        //发起提现请求
        $params = curlRequest($url,$xml,'post',true);

        //xml转数组
        $array = $wx::xmlToArray($params);

        return $array;
    }
}